<template>
	<view class="container">
		<js-error mode="top" ref="jsError" z-index="999"></js-error>
		<view style="padding: 0;margin: 0;position: absolute;top: 0;width: 100%;text-align: center;height: 200px;">
			<image src='/static/image/index2.png' style="width: 98%;border-radius: 5%;height: 210px;"></image>
		</view>
		<view style="padding: 0;margin: 0;position: absolute;top: 210px;bottom: 20px;width: 100%;text-align: center;overflow: auto;">
			<view class="cu-bar bg-white solid-bottom margin-top">
				<view class="action">
					<text style="font-size:large;font: bolder;">扫码</text>
				</view>
			</view>
			<u-grid :col="2">
				<u-grid-item @click="Over('1')" style="padding: 2%;">
					<image src='/static/image/commit.png' style="width: 50px;height: 50px;"></image>
					<view class="grid-text">产成品入库</view>
				</u-grid-item>
				<u-grid-item @click="Over('5','调出')" style="padding: 2%;">
					<image src='/static/image/goout.png' style="width: 50px;height: 50px;"></image>
					<view class="grid-text">仓库调拨-调出</view>
				</u-grid-item>

				<u-grid-item @click="Over('5','调入')" style="padding: 2%;">
					<image src='/static/image/enter4.png' style="width: 50px;height: 50px;"></image>
					<view class="grid-text">仓库调拨-调入</view>
				</u-grid-item>
				<u-grid-item @click="Over('4')" style="padding: 2%;">
					<image src='/static/image/invert.png' style="width: 50px;height: 50px;"></image>
					<view class="grid-text">货位调整</view>
				</u-grid-item>

				
			</u-grid>
		</view>
		<u-popup v-model="show" mode="bottom" height="60%" :closeable='true'>
			<view style="padding: 10px;font-size: 18px;">
				请先选择仓库：
			</view>
			<view>
				<u-form class="form bg-white" :model="model" ref="uForm" label-position="left">
					<u-form-item label="" prop="testCarVen" label-width="200" required
						:label-style="{'font-weight':'bold'}">
						<js-select v-model="model.cWhCode" :items="carVenSelectList" placeholder="请选择仓库" :tree="false"
							:label-value="model.cWhName" @label-input="model.cWhName = $event">
						</js-select>

					</u-form-item>
				</u-form>
				<view style="padding: 10px;height: 100px;">
					<!-- <u-button size="mini" style="margin: 0 10px 10px 0;" @click="ckSelect(item)" v-for="(item,index) in this.vuex_vague"
						:key="index">{{item.cWhName}}</u-button> -->
				</view>
				<view style="position: relative;bottom: -160px; padding: 0 10px;">
					<u-button type="primary" @click="toOver">确定选择</u-button>
				</view>
			</view>

		</u-popup>
	</view>
	</view>

</template>

<script>
	import {
		mapState
	} from 'vuex';
	export default {

		data() {
			return {
				cWhType: '',
				model: {
					cWhCode: '',
					cWhName: '',
				},
				carVenSelectList: [],
				show: false,
				listc: [],
				listx: [],
				listh: [],

			};
		},
		onLoad() {
			this.loadData();
		},
		computed: {
			...mapState(['vuex_vague', 'vuex_vague4', 'vuex_vague5'])
		},
		methods: {
			ckSelect(item) {
				console.log(item)
				// this.$store.commit("modifyVague",res.subdata)
			},
			toOver() {
				let obj = {};
				if (this.model.cWhCode) {
					this.carVenSelectList.forEach(item => {
						if (this.model.cWhCode == item.cWhCode) {
							obj = item;
						}
					})
					obj.cWhType = this.cWhType;
					if (this.cWhType == '1') {
						this.vuex_vague.push(obj)
						uni.navigateTo({
							url: '/pages/tm/index/tmCcprk/list?cWhData=' + JSON.stringify(obj),
						})
					} else if (this.cWhType == '4') {
						this.vuex_vague4.push(obj)
						uni.navigateTo({
							url: '/pages/tm/index/tmHwtz/list?cWhData=' + JSON.stringify(obj),
						})
					} else if (this.cWhType == '5') {
						this.vuex_vague5.push(obj)
						// 仓库调拨—调出
						uni.navigateTo({
							url: '/pages/tm/index/tmCkdb/outList?cWhData=' + JSON.stringify(obj),
						})
					} else if (this.cWhType == '6') {
						this.vuex_vague5.push(obj)
						// 仓库调拨—调入
						uni.navigateTo({
							url: '/pages/tm/index/tmCkdb/inList?cWhData=' + JSON.stringify(obj),
						})
					}
					this.show = false
				} else {
					this.$refs.jsError.showError('', '请先选择仓库！', 'info');
				}

			},
			// 成品入库
			Over(cWhType, flag = '') {
				this.cWhType = cWhType;

				if (flag == '调出') {
					this.cWhType = '5';
				} else if (flag == '调入') {
					this.cWhType = '6';
				}
				this.model = {
					cWhCode: '',
					cWhName: '',
				};
				// console.log(this.vuex_cpcrk, 'this.vuex_cpcrk==')
				// console.log(this.vuex_ckdbOut, 'vuex_ckdbOut==')
				// console.log(this.vuex_ckdbIn, 'vuex_ckdbIn==')
				// console.log(this.vuex_hwtz, 'this.vuex_hwtz==')
				if (
					!this.vuex_cpcrk.cWhCode && this.cWhType == '1' ||
					!this.vuex_hwtz.cWhCode && this.cWhType == '4' ||
					!this.vuex_ckdbOut.cWhCode && this.cWhType == '5' ||
					!this.vuex_ckdbIn.cWhCode && this.cWhType == '6'
				) {
					this.$u.api.tm.getWarehouse({
							cWhCode: '',
							cWhType
						})
						.then(res => {
							if (res.statecode == '1') {
								this.carVenSelectList = res.subdata.map(item => {
									item.name = item.cWhName;
									item.value = item.cWhCode;
									return item
								})
								this.show = true

							} else {
								this.$u.toast(res.message);
							}
						});
				} else {
					let obj = {};
					obj.cWhType = this.cWhType;

					if (cWhType == '1') {
						obj = {
							...obj,
							...this.vuex_cpcrk
						};
						uni.navigateTo({
							url: '/pages/tm/index/tmCcprk/list?cWhData=' + JSON.stringify(obj),
						})
					} else if (cWhType == '4') {
						obj = {
							...obj,
							...this.vuex_hwtz
						};
						uni.navigateTo({
							url: '/pages/tm/index/tmHwtz/list?cWhData=' + JSON.stringify(obj),
						})
					} else if (cWhType == '5' && flag == '调出') {
						obj = {
							...obj,
							...this.vuex_ckdbOut
						};
						// 仓库调拨—调出
						uni.navigateTo({
							url: '/pages/tm/index/tmCkdb/outList?cWhData=' + JSON.stringify(obj),
						})
					} else if (cWhType == '5' && flag == '调入') {
						obj = {
							...obj,
							...this.vuex_ckdbIn
						};
						// 仓库调拨—调入
						uni.navigateTo({
							url: '/pages/tm/index/tmCkdb/inList?cWhData=' + JSON.stringify(obj),
						})
					}
				}


			},
			navTo(url) {
				uni.navigateTo({
					url: url
				});
			},


			showModal(e) {
				this.modalName = e.currentTarget.dataset.target
			},
			hideModal(e) {
				this.modalName = null
			},
			Gridchange(e) {
				this.gridCol = e.detail.value
			},
			Gridswitch(e) {
				this.gridBorder = e.detail.value
			},
			MenuBorder(e) {
				this.menuBorder = e.detail.value
			},
			MenuArrow(e) {
				this.menuArrow = e.detail.value
			},
			MenuCard(e) {
				this.menuCard = e.detail.value
			},
			SwitchSex(e) {
				this.skin = e.detail.value
			},

			// ListTouch触摸开始
			ListTouchStart(e) {
				this.listTouchStart = e.touches[0].pageX
			},

			// ListTouch计算方向
			ListTouchMove(e) {
				this.listTouchDirection = e.touches[0].pageX - this.listTouchStart > 0 ? 'right' : 'left'
			},

			// ListTouch计算滚动
			ListTouchEnd(e) {
				if (this.listTouchDirection == 'left') {
					this.modalName = e.currentTarget.dataset.target
				} else {
					this.modalName = null
				}
				this.listTouchDirection = null
			},
			/**
			 * 请求静态数据只是为了代码不那么乱
			 * 分次请求未作整合
			 */
			async loadData() {

			},
			navToDetailUrl(char) {

			},
		},
	}
</script>

<style lang="scss">
	/* #ifdef MP */
	page {
		.cate-section {
			position: relative;
			z-index: 5;
			border-radius: 16upx 16upx 0 0;
			margin-top: -20upx;
		}

		.carousel-section {
			padding: 0;

			.titleNview-placing {
				padding-top: 0;
				height: 0;
			}

			.carousel {
				.carousel-item {
					padding: 0;
				}
			}

			.swiper-dots {
				left: 45upx;
				bottom: 40upx;
			}
		}

		text {
			font-size: 60upx;
		}
	}

	/* #endif */
	page {
		background: #ffffff;
	}
</style>